package android.moodle;

import android.Graphics.GameRenderer;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public class GameActivity extends Activity
{
    private GameRenderer renderer;
    private GLSurfaceView glView;
    private TextView gameHeader;

    /** Called when the activity is first created. */
    @Override
    public void onCreate( Bundle savedInstanceState )
    {
        super.onCreate( savedInstanceState );
        setContentView(R.layout.gamescreen);

        final Vibrator v = (Vibrator) getSystemService( Context.VIBRATOR_SERVICE );

        // Get the width and height of the screen, so it's scalable
        Display display = getWindowManager().getDefaultDisplay();
        float width = display.getWidth();

        // Subtracts 25 pixels because that is the height of the statusbar
        float height = display.getHeight() - 25;

        //Declares the GLSurfaceView that is used for drawing the game
        glView = (GLSurfaceView) findViewById(R.id.glsurfaceview);

        //Declares the Gamerenderer that is used to draw the game
        renderer = new GameRenderer( this, width, height, 3, 3 );
        glView.setRenderer( renderer );

        gameHeader = (TextView) findViewById(R.id.gameheader);

        glView.setOnTouchListener( new View.OnTouchListener()
        {
            public boolean onTouch( View view, MotionEvent motionEvent )
            {
                v.vibrate(100);
                renderer.drawSymbol(motionEvent.getX(), motionEvent.getY());
                gameHeader.setText( renderer.getHeader() );
                return false;
            }
        });
    }
}